/*
 * Created by Neville Kadwa.
 */
package org.shiftone.cdep.model;

import org.shiftone.cdep.util.ClassFilter;
import org.shiftone.cdep.util.NullIterator;

import java.util.Iterator;
import java.util.HashSet;

public class MethodInfo
{

    private String name;
    private String signature;
    private int methodId;

    private HashSet calls;

    public MethodInfo(String name, String signature)
    {
        this.name = name;
        this.signature = signature;
    }

    public String getName()
    {
        return name;
    }

    public String getSignature()
    {
        return signature;
    }

    public void addMethodCall(String callClass, String method, String signature)
    {
        if (!ClassFilter.acceptClass(callClass))
            return;

        if (calls == null)
            calls = new HashSet();
        calls.add(new MethodCallInfo(callClass, method, signature));
    }

    public Iterator getMethodCalls()
    {
        return (calls == null) ? NullIterator.getNullIterator() : calls.iterator();
    }

    public boolean hasMethodCalls()
    {
        return (calls != null) && (calls.size() > 0);
    }

    public static class MethodCallInfo
    {
        public String callClass;
        public String method;
        public String signature;

        public MethodCallInfo(String callClass, String method, String signature)
        {
            this.callClass = callClass;
            this.method = method;
            this.signature = signature;
        }

        public boolean equals(Object o)
        {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            final MethodCallInfo that = (MethodCallInfo) o;

            if (callClass != null ? !callClass.equals(that.callClass) : that.callClass != null) return false;
            if (method != null ? !method.equals(that.method) : that.method != null) return false;
            if (signature != null ? !signature.equals(that.signature) : that.signature != null) return false;

            return true;
        }

        public int hashCode()
        {
            int result;
            result = (callClass != null ? callClass.hashCode() : 0);
            result = 29 * result + (method != null ? method.hashCode() : 0);
            result = 29 * result + (signature != null ? signature.hashCode() : 0);
            return result;
        }
    }

    public int getMethodId()
    {
        return methodId;
    }

    public void setMethodId(int methodId)
    {
        this.methodId = methodId;
    }
}
